<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
    request.setAttribute("basePath", request.getContextPath());

    String appid = request.getParameter("appid");
%>
<html>
<head>
    <%@include file="../../common/include_list_head.jsp" %>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script type="text/javascript" src="${basePath}/resources/jquery/jquery-1.6.4.min.js"></script>
    <script type="text/javascript" src="${basePath}/resources/js/common/json2.js"></script>
    <link rel="stylesheet" href="${basePath}/component/JQueryzTreev3.5.14/css/zTreeStyle/zTreeStyle.css"
          type="text/css">
    <script type="text/javascript" src="${basePath}/component/JQueryzTreev3.5.14/js/jquery.ztree.core-3.5.js"></script>
    <script type="text/javascript"
            src="${basePath}/component/JQueryzTreev3.5.14/js/jquery.ztree.excheck-3.5.min.js"></script>
    <script type="text/javascript"
            src="${basePath}/component/JQueryzTreev3.5.14/js/jquery.ztree.exhide-3.5.min.js"></script>

    <script>
        $(function () {
            var url ="idMenu-getMenues.action?"+(new Date()).getTime();
           // '${basePath}/s/lb/l'
            $.get(url, function (data) {
                var zNodes = new Array();
                $.each($.parseJSON(data), function (i, item) {
                    var obj = new Object();
                    obj.id = item.id;
                    obj.pId = item.parentid;
                    obj.name = item.text;
                    if (item.id.length == 3) {
                        obj.open = true;
                    }
                    zNodes.push(obj);
                });

                var setting = {
                    data: {
                        simpleData: {
                            enable: true
                        }
                    },
                    check: {
                        enable: true,
                        chkStyle: "checkbox",
                        chkboxType:{ "Y":"s", "N":"s" }
                    }
                };
                $.fn.zTree.init($("#tree"), setting, zNodes);
            });
        });

        function doSave(){
            var treeObj=$.fn.zTree.getZTreeObj("tree");
            var  nodes=treeObj.getCheckedNodes(true);
            var v ="";
            for(var i=0;i<nodes.length;i++){
                var nodeChildrens=nodes[i].children;
                if(!nodeChildrens) {
                    if(v!=""){
                        v+= ",";
                    }
                    v += nodes[i].id;
                }
            }
            var url = "idMenu-saveBatchService.action?"+(new Date()).getTime();
            var upmenuid = $("#upmenuid").val();
            $.post(url,{
                menuids : v,
                upmenuid :upmenuid
            },function (data) {
                alert("批量添加服务成功");
                parent.closeEntityWindow();
            });


        }

    </script>
    <style>
        .button {
            background: url("form/btn_bg.jpg") repeat scroll 0 0 transparent;
            border: 1px solid #aabbcc;
            font-size: 12px;
            height: 24px;
            line-height: 22px;
        }
    </style>
</head>
<body>
<input type="hidden" value="${wid}" id="upmenuid"/>
<div class="treeDiv">
    <fieldset style="margin: 20px;">
        <legend>批量添加服务到门户</legend>
        <ul id="tree" class="ztree"></ul>
    </fieldset>
</div>

<div style="text-align: center;">
    <table transMode="true" style="width: 100%;text-align: center;">
        <tr>
            <td colspan="4" style="border: medium none;padding-bottom: 3px;padding-top: 3px;text-align: center;">
                <input type="button" id="ysSaveButton" value=" 保 存 " onclick="doSave()" class="button"/>
                <input type="button" value=" 关 闭 " onclick="parent.closeEntityWindow()" class="button"/>
                <s:if test="actionErrors.size()>0 || actionMessages.size()>0 || fieldErrors.size()>0">
						<span id="SystemErrorMessage" style="top: 20px">
							<s:actionerror cssStyle="color:red"/>
							<s:actionmessage cssStyle="color:blue"/>
							<s:fielderror/>
						</span>
                </s:if>
            </td>
        </tr>
    </table>
</div>

</body>
</html>
